package com.shop.front.dao.user;

import com.shop.domain.user.UserAddress;
import com.shop.jpa.BaseDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserAddressDao extends BaseDao<UserAddress, Long> {

    @Modifying(clearAutomatically = true)
    @Query("update UserAddress set isDefault = 0 where isDefault = 1 and uid = ?1")
    public int updateNotDefault(Long userId);

    @Query("from UserAddress where isDefault = 1 and uid = ?1")
    public UserAddress findDefault(Long userId);

    @Query("from UserAddress where uid = ?1 order by isDefault desc, id desc")
    public List<UserAddress> findByUid(Long userId);

}
